Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
How to remove the "T" value in datetime-local input type?

I am using datetime-local input type in HTML, but I don't want to use the "T" on the output. I want to only get the date and time with a space between.

<input type="datetime-local" id="date" name="date">

The output is:

2021-11-08T16:34

What i want is:

2021-11-08 16:34

What do i need to do to get this output?

PS: Try to help me without bootstrap libraries, because on this project i can't use it.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As Dima Parzhitsky wrote, consider to use Intl.DateTimeFormat methods

const
  localDt =_=>
    {
    let now = new Date()
    now.setMinutes(now.getMinutes() - now.getTimezoneOffset())
    now.setSeconds(0)       // remove seconds
    now.setMilliseconds(0) // remove milliseconds
    return now
    }
, fxDate = 
    Intl.DateTimeFormat( undefined,
    { hour12: false, year: 'numeric', month: '2-digit'
    , day: '2-digit', hour: '2-digit', minute: '2-digit'
    })
, dtForm = d => 
    {
    let {day,month,year,hour,minute} = 
      fxDate.formatToParts(d).reduce((o,{type,value})=>(o[type]=value,o),{})
    return `${year}-${month}-${day} ${hour}:${minute}`
    }


dateInput.valueAsDate = localDt()  // init date value 

getDate.onclick =_=>
  {
  let dt = dateInput.valueAsDate
  dt.setMinutes(dt.getMinutes() + dt.getTimezoneOffset())

  dateStr.textContent = dtForm(dt) 
  }
<input type="datetime-local" id="dateInput">
<br><br>
<button id="getDate">get Date</button>


<p id="dateStr">???</p>

about 4 years ago · Juan Pablo Isaza Report

0

You can try this, I use pure javascript

//get the date
  var x = document.getElementById("date").value;

//this replaces the 'T' with an space
  x = x.replace("T", " ");

//this places the string back on the HTML page
  document.getElementById("demo").innerHTML = x;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!